<template>
  <section class="jumbotron">
    <h3 class="jumbotron-heading">github用户搜索</h3>
    <div>
      <input
        v-model="search"
        type="text"
        placeholder="请输入搜索内容"
        @keyup.enter="searchUserInfoHandle"
      />&nbsp;<button @click="searchUserInfoHandle">搜索</button>
    </div>
  </section>
</template>

<script>
import axios from "axios";
export default {
  props: ["getHeaderData"],
  name: "Header",
  data() {
    return {
      search: "",
    };
  },
  methods: {
    async searchUserInfoHandle() {
      //在点击搜索按钮后,发送请求前 修改数据
      if (!this.search) return alert("输入内容不可为空");
      this.getHeaderData({ isInit: false, isLoading: true });
      const result = await axios.get(
        `https://api.github.com/search/users?q=${this.search}`
      );
      //console.log(result.data.items);
      this.getHeaderData({
        isLoading: false,
        data: result.data.items,
      });
      this.search = "";
    },
  },
};
</script>

<style>
</style>